﻿using Kenly.DBFramework.Gateway;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Collections.Generic;
using System;
using System.Runtime;

using Kenly.DBFramework.TestModel.Purchasing;

namespace Kenly.DBFramework.Tests
{

    /// <summary>
    ///这是 ViewGatewayAggregateTest 的测试类，旨在
    ///包含所有 ViewGatewayAggregateTest 单元测试
    ///</summary>
    [TestClass()]
    public class ViewGatewayAggregateTest
    {
        private TestContext testContextInstance;

        /// <summary>
        ///获取或设置测试上下文，上下文提供
        ///有关当前测试运行及其功能的信息。
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region 附加测试属性
        // 
        //编写测试时，还可使用以下属性:
        //
        //使用 ClassInitialize 在运行类中的第一个测试前先运行代码
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //使用 ClassCleanup 在运行完类中的所有测试后再运行代码
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}

        //使用 TestInitialize 在运行每个测试前先运行代码
        [TestInitialize()]
        public void MyTestInitialize()
        {
        }

        //使用 TestCleanup 在运行完每个测试后运行代码
        [TestCleanup()]
        public void MyTestCleanup()
        {

        }

        #endregion

        [TestMethod()]
        public void CountAllTest()
        {
            string msg = "Vendor.CountAll did not return expected value.";

            int count = Vendor.CountAll();

            Assert.IsTrue(count > 0, msg);
        }

        [TestMethod()]
        public void CountActiveTest()
        {
            string msg = "Vendor.CountActive did not return expected value.";

            int activeCount = Vendor.CountActive();
            int totalCount = Vendor.CountAll();

            List<VendorCountGroup> countGroups = VendorCountGroup.Execute();
            foreach (VendorCountGroup item in countGroups)
            {
                if (item.ActiveFlag)
                {
                    Assert.IsTrue(item.VendorCount == activeCount, 
                        msg + "activeCount=" + activeCount);
                }
                else
                {
                    Assert.IsTrue(item.VendorCount == (totalCount-activeCount),
                        msg + "activeCount=" + activeCount);
                }
            }
        }

        [TestMethod()]
        public void CountGroupByActiveFlagTest()
        {
            string msg = "Vendor.CountGroupByActiveFlag did not return expected value.";

            List<int> counts = Vendor.CountGroupByActiveFlag();

            Assert.IsTrue(counts.Count==2, msg);
        }
    }
}
